using Senparc.Weixin.Entities;
using System;
namespace Senparc.Weixin.Context
{
	public class MessageContext<TRequest, TResponse> : IMessageContext<TRequest, TResponse> where TRequest : IRequestMessageBase where TResponse : IResponseMessageBase
	{
		private int _maxRecordCount;
		public virtual event EventHandler<WeixinContextRemovedEventArgs<TRequest, TResponse>> MessageContextRemoved = null;
		public string UserName
		{
			get;
			set;
		}
		public DateTime LastActiveTime
		{
			get;
			set;
		}
		public MessageContainer<TRequest> RequestMessages
		{
			get;
			set;
		}
		public MessageContainer<TResponse> ResponseMessages
		{
			get;
			set;
		}
		public int MaxRecordCount
		{
			get
			{
				return this._maxRecordCount;
			}
			set
			{
				this.RequestMessages.MaxRecordCount = value;
				this.ResponseMessages.MaxRecordCount = value;
				this._maxRecordCount = value;
			}
		}
		public object StorageData
		{
			get;
			set;
		}
		public double? ExpireMinutes
		{
			get;
			set;
		}
		public AppStoreState AppStoreState
		{
			get;
			set;
		}
		private void OnMessageContextRemoved(WeixinContextRemovedEventArgs<TRequest, TResponse> e)
		{
			EventHandler<WeixinContextRemovedEventArgs<TRequest, TResponse>> messageContextRemoved = this.MessageContextRemoved;
			if (messageContextRemoved != null)
			{
				messageContextRemoved(this, e);
			}
		}
		public MessageContext()
		{
			this.RequestMessages = new MessageContainer<TRequest>(this.MaxRecordCount);
			this.ResponseMessages = new MessageContainer<TResponse>(this.MaxRecordCount);
			this.LastActiveTime = DateTime.Now;
		}
		public virtual void OnRemoved()
		{
			WeixinContextRemovedEventArgs<TRequest, TResponse> e = new WeixinContextRemovedEventArgs<TRequest, TResponse>(this);
			this.OnMessageContextRemoved(e);
		}
	}
}
